/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header: https://192.168.1.224/svn/elancom/product/elancom-platform/trunk/src/main/java/com/elancom/framework/dao/expression/Empty.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Id: Empty.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Author: lanzhouxue $
 * $Date: 2012-07-02 11:09:12 +0800 (周一, 02 七月 2012) $
 * $Revision: 1034 $
 */
package com.elancom.framework.dao.expression;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

/**
 * 如果用于HQL，则propertyName为一个子查询
 * 
 * @author elancom
 * @date May 4, 2012
 */
public class Empty implements Condition {
	private static final long serialVersionUID = -3487523862354673650L;

	private final String propertyName;

	public Empty(String propertyName) {
		super();
		this.propertyName = propertyName;
	}

	@Override
	public Criterion toCriterion() {
		return Restrictions.isEmpty(propertyName);
	}

	@Override
	public String toHQLString() {
		final StringBuilder sb = new StringBuilder();
		sb.append("not exists (").append(propertyName).append(")");
		return sb.toString();
	}

}
